<template>
  <div class="net-new-disc">
    <div class="arrow-left" @click="handleToPrev"></div>
    <div class="arrow-right" @click="handleToNext"></div>
    <n-carousel trigger="hover" dot-type="line" ref="carouselRef">
      <template v-for="item in discs" :key="item">
        <div class="disc">
          <template v-for="subitem in item" :key="subitem">
            <div class="disc-item-wrap">
              <div class="disc-item">
                <img :src="subitem.picUrl" />
              </div>
              <div class="disc-text">
                <div class="disc-text-album">{{ subitem.name }}</div>
                <div class="disc-text-singer">{{ subitem.artist.name }}</div>
              </div>
            </div>
          </template>
        </div>
      </template>
    </n-carousel>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, ref } from 'vue'

import { NCarousel } from 'naive-ui'
import newDiscProps from './props'

export default defineComponent({
  components: {
    NCarousel
  },
  props: newDiscProps,
  setup(props) {
    const discs = computed(() => props.discs)
    const carouselRef = ref<InstanceType<typeof NCarousel>>()
    const handleToNext = () => {
      carouselRef.value && carouselRef.value.next()
    }
    const handleToPrev = () => {
      carouselRef.value && carouselRef.value.prev()
    }

    return {
      discs,
      carouselRef,
      handleToNext,
      handleToPrev
    }
  }
})
</script>

<style scoped lang="less">
.net-new-disc {
  background: #f5f5f5;
  border: 1px solid #ccc;
  padding: 0px 15px;
  position: relative;
  .arrow-left {
    position: absolute;
    z-index: 10;
    top: 35%;
    left: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    background: url('../../../assets/arrow-left.png');
    background-size: cover;
  }
  .arrow-right {
    position: absolute;
    z-index: 10;
    top: 35%;
    right: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    background: url('../../../assets/arrow-right.png');
    background-size: cover;
  }
  .disc {
    width: 95%;
    margin: 10px auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .disc-item-wrap {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      .disc-item {
        width: 95px;
        height: 82px;
        background: url('../../../assets/disk.png');
        background-size: cover;
        img {
          width: 83px;
          height: 83px;
        }
      }
      .disc-text {
        width: 100px;
        color: #666;
        .disc-text-album {
          font-size: 10px;
          transform: scale(0.8);
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          &:hover {
            cursor: pointer;
            text-decoration: underline;
          }
        }
        .disc-text-singer {
          font-size: 10px;
          transform: scale(0.8);
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          &:hover {
            cursor: pointer;
            text-decoration: underline;
          }
        }
      }
    }
  }
}
</style>
